{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Apriori算法实战"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "#数据加载\n",
    "dataset = pd.read_csv('./Market_Basket_Optimisation.csv',header=None)\n",
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 把数据存放在transactions\n",
    "transactions = []\n",
    "for i in range(0,dataset.shape[0]):\n",
    "    temp = []\n",
    "    for j in range(0,dataset.shape[1]):\n",
    "        if str(dataset.values[i,j]) != 'nan':\n",
    "            temp.append(str(dataset.values[i,j]))\t\n",
    "    # print(temp)\n",
    "    transactions.append(temp)\n",
    "# print(transactions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 采用efficient_apriori工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "metadata": {},
   "outputs": [],
   "source": [
    "from efficient_apriori import apriori\n",
    "itemsets, rules = apriori(transactions,min_support=0.02,min_confidence=0.25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: {('olive oil',): 494,\n",
       "  ('salmon',): 319,\n",
       "  ('almonds',): 153,\n",
       "  ('tomato juice',): 228,\n",
       "  ('green tea',): 991,\n",
       "  ('honey',): 356,\n",
       "  ('frozen smoothie',): 475,\n",
       "  ('low fat yogurt',): 574,\n",
       "  ('cottage cheese',): 239,\n",
       "  ('energy drink',): 200,\n",
       "  ('vegetables mix',): 193,\n",
       "  ('shrimp',): 536,\n",
       "  ('avocado',): 250,\n",
       "  ('mineral water',): 1788,\n",
       "  ('burgers',): 654,\n",
       "  ('eggs',): 1348,\n",
       "  ('meatballs',): 157,\n",
       "  ('turkey',): 469,\n",
       "  ('milk',): 972,\n",
       "  ('whole wheat rice',): 439,\n",
       "  ('energy bar',): 203,\n",
       "  ('whole wheat pasta',): 221,\n",
       "  ('french fries',): 1282,\n",
       "  ('soup',): 379,\n",
       "  ('spaghetti',): 1306,\n",
       "  ('frozen vegetables',): 715,\n",
       "  ('cookies',): 603,\n",
       "  ('cooking oil',): 383,\n",
       "  ('champagne',): 351,\n",
       "  ('oil',): 173,\n",
       "  ('chocolate',): 1229,\n",
       "  ('chicken',): 450,\n",
       "  ('tomatoes',): 513,\n",
       "  ('fresh tuna',): 167,\n",
       "  ('red wine',): 211,\n",
       "  ('pepper',): 199,\n",
       "  ('ham',): 199,\n",
       "  ('pancakes',): 713,\n",
       "  ('grated cheese',): 393,\n",
       "  ('fresh bread',): 323,\n",
       "  ('ground beef',): 737,\n",
       "  ('escalope',): 595,\n",
       "  ('herb & pepper',): 371,\n",
       "  ('strawberries',): 160,\n",
       "  ('cake',): 608,\n",
       "  ('hot dogs',): 243,\n",
       "  ('brownies',): 253,\n",
       "  ('cereals',): 193,\n",
       "  ('muffins',): 181,\n",
       "  ('light mayo',): 204,\n",
       "  ('yogurt cake',): 205,\n",
       "  ('butter',): 226,\n",
       "  ('french wine',): 169},\n",
       " 2: {('frozen smoothie', 'mineral water'): 152,\n",
       "  ('green tea', 'mineral water'): 233,\n",
       "  ('low fat yogurt', 'mineral water'): 180,\n",
       "  ('mineral water', 'olive oil'): 207,\n",
       "  ('mineral water', 'shrimp'): 177,\n",
       "  ('burgers', 'eggs'): 216,\n",
       "  ('milk', 'mineral water'): 360,\n",
       "  ('mineral water', 'whole wheat rice'): 151,\n",
       "  ('frozen vegetables', 'spaghetti'): 209,\n",
       "  ('green tea', 'spaghetti'): 199,\n",
       "  ('burgers', 'mineral water'): 183,\n",
       "  ('cooking oil', 'mineral water'): 151,\n",
       "  ('eggs', 'mineral water'): 382,\n",
       "  ('chicken', 'mineral water'): 171,\n",
       "  ('eggs', 'spaghetti'): 274,\n",
       "  ('mineral water', 'spaghetti'): 448,\n",
       "  ('mineral water', 'tomatoes'): 183,\n",
       "  ('spaghetti', 'tomatoes'): 157,\n",
       "  ('french fries', 'milk'): 178,\n",
       "  ('chocolate', 'eggs'): 249,\n",
       "  ('mineral water', 'pancakes'): 253,\n",
       "  ('pancakes', 'spaghetti'): 189,\n",
       "  ('milk', 'spaghetti'): 266,\n",
       "  ('ground beef', 'milk'): 165,\n",
       "  ('ground beef', 'mineral water'): 307,\n",
       "  ('ground beef', 'spaghetti'): 294,\n",
       "  ('chocolate', 'french fries'): 258,\n",
       "  ('chocolate', 'mineral water'): 395,\n",
       "  ('eggs', 'french fries'): 273,\n",
       "  ('french fries', 'mineral water'): 253,\n",
       "  ('frozen vegetables', 'mineral water'): 268,\n",
       "  ('chocolate', 'frozen vegetables'): 172,\n",
       "  ('cake', 'mineral water'): 206,\n",
       "  ('french fries', 'green tea'): 214,\n",
       "  ('french fries', 'pancakes'): 151,\n",
       "  ('chocolate', 'green tea'): 176,\n",
       "  ('chocolate', 'spaghetti'): 294,\n",
       "  ('chocolate', 'ground beef'): 173,\n",
       "  ('chocolate', 'milk'): 241,\n",
       "  ('frozen vegetables', 'milk'): 177,\n",
       "  ('mineral water', 'soup'): 173,\n",
       "  ('olive oil', 'spaghetti'): 172,\n",
       "  ('burgers', 'french fries'): 165,\n",
       "  ('burgers', 'spaghetti'): 161,\n",
       "  ('french fries', 'spaghetti'): 207,\n",
       "  ('shrimp', 'spaghetti'): 159,\n",
       "  ('eggs', 'green tea'): 191,\n",
       "  ('eggs', 'milk'): 231,\n",
       "  ('eggs', 'pancakes'): 163,\n",
       "  ('eggs', 'frozen vegetables'): 163}}"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#频繁项集\n",
    "itemsets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{frozen smoothie} -> {mineral water},\n",
       " {low fat yogurt} -> {mineral water},\n",
       " {olive oil} -> {mineral water},\n",
       " {shrimp} -> {mineral water},\n",
       " {burgers} -> {eggs},\n",
       " {milk} -> {mineral water},\n",
       " {whole wheat rice} -> {mineral water},\n",
       " {frozen vegetables} -> {spaghetti},\n",
       " {burgers} -> {mineral water},\n",
       " {cooking oil} -> {mineral water},\n",
       " {eggs} -> {mineral water},\n",
       " {chicken} -> {mineral water},\n",
       " {spaghetti} -> {mineral water},\n",
       " {mineral water} -> {spaghetti},\n",
       " {tomatoes} -> {mineral water},\n",
       " {tomatoes} -> {spaghetti},\n",
       " {pancakes} -> {mineral water},\n",
       " {pancakes} -> {spaghetti},\n",
       " {milk} -> {spaghetti},\n",
       " {ground beef} -> {mineral water},\n",
       " {ground beef} -> {spaghetti},\n",
       " {chocolate} -> {mineral water},\n",
       " {frozen vegetables} -> {mineral water},\n",
       " {cake} -> {mineral water},\n",
       " {soup} -> {mineral water},\n",
       " {olive oil} -> {spaghetti},\n",
       " {burgers} -> {french fries},\n",
       " {shrimp} -> {spaghetti}]"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#关联规则\n",
    "rules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>关联规则</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{frozen smoothie} -&gt; {mineral water} (conf: 0.320, supp: 0.020, lift: 1.342, conv: 1.120)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{low fat yogurt} -&gt; {mineral water} (conf: 0.314, supp: 0.024, lift: 1.316, conv: 1.110)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{olive oil} -&gt; {mineral water} (conf: 0.419, supp: 0.028, lift: 1.758, conv: 1.311)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{shrimp} -&gt; {mineral water} (conf: 0.330, supp: 0.024, lift: 1.385, conv: 1.137)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{burgers} -&gt; {eggs} (conf: 0.330, supp: 0.029, lift: 1.838, conv: 1.225)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>{milk} -&gt; {mineral water} (conf: 0.370, supp: 0.048, lift: 1.554, conv: 1.210)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>{whole wheat rice} -&gt; {mineral water} (conf: 0.344, supp: 0.020, lift: 1.443, conv: 1.161)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>{frozen vegetables} -&gt; {spaghetti} (conf: 0.292, supp: 0.028, lift: 1.679, conv: 1.167)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>{burgers} -&gt; {mineral water} (conf: 0.280, supp: 0.024, lift: 1.174, conv: 1.058)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>{cooking oil} -&gt; {mineral water} (conf: 0.394, supp: 0.020, lift: 1.654, conv: 1.257)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>{eggs} -&gt; {mineral water} (conf: 0.283, supp: 0.051, lift: 1.189, conv: 1.063)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>{chicken} -&gt; {mineral water} (conf: 0.380, supp: 0.023, lift: 1.594, conv: 1.228)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>{spaghetti} -&gt; {mineral water} (conf: 0.343, supp: 0.060, lift: 1.439, conv: 1.159)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>{mineral water} -&gt; {spaghetti} (conf: 0.251, supp: 0.060, lift: 1.439, conv: 1.102)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>{tomatoes} -&gt; {mineral water} (conf: 0.357, supp: 0.024, lift: 1.497, conv: 1.184)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>{tomatoes} -&gt; {spaghetti} (conf: 0.306, supp: 0.021, lift: 1.758, conv: 1.190)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>{pancakes} -&gt; {mineral water} (conf: 0.355, supp: 0.034, lift: 1.489, conv: 1.181)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>{pancakes} -&gt; {spaghetti} (conf: 0.265, supp: 0.025, lift: 1.522, conv: 1.124)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>{milk} -&gt; {spaghetti} (conf: 0.274, supp: 0.035, lift: 1.572, conv: 1.137)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>{ground beef} -&gt; {mineral water} (conf: 0.417, supp: 0.041, lift: 1.748, conv: 1.305)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>{ground beef} -&gt; {spaghetti} (conf: 0.399, supp: 0.039, lift: 2.291, conv: 1.374)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>{chocolate} -&gt; {mineral water} (conf: 0.321, supp: 0.053, lift: 1.348, conv: 1.122)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>{frozen vegetables} -&gt; {mineral water} (conf: 0.375, supp: 0.036, lift: 1.572, conv: 1.218)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>{cake} -&gt; {mineral water} (conf: 0.339, supp: 0.027, lift: 1.421, conv: 1.152)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>{soup} -&gt; {mineral water} (conf: 0.456, supp: 0.023, lift: 1.915, conv: 1.401)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>{olive oil} -&gt; {spaghetti} (conf: 0.348, supp: 0.023, lift: 2.000, conv: 1.267)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>{burgers} -&gt; {french fries} (conf: 0.252, supp: 0.022, lift: 1.476, conv: 1.109)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>{shrimp} -&gt; {spaghetti} (conf: 0.297, supp: 0.021, lift: 1.704, conv: 1.174)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                           关联规则\n",
       "0     {frozen smoothie} -> {mineral water} (conf: 0.320, supp: 0.020, lift: 1.342, conv: 1.120)\n",
       "1      {low fat yogurt} -> {mineral water} (conf: 0.314, supp: 0.024, lift: 1.316, conv: 1.110)\n",
       "2           {olive oil} -> {mineral water} (conf: 0.419, supp: 0.028, lift: 1.758, conv: 1.311)\n",
       "3              {shrimp} -> {mineral water} (conf: 0.330, supp: 0.024, lift: 1.385, conv: 1.137)\n",
       "4                      {burgers} -> {eggs} (conf: 0.330, supp: 0.029, lift: 1.838, conv: 1.225)\n",
       "5                {milk} -> {mineral water} (conf: 0.370, supp: 0.048, lift: 1.554, conv: 1.210)\n",
       "6    {whole wheat rice} -> {mineral water} (conf: 0.344, supp: 0.020, lift: 1.443, conv: 1.161)\n",
       "7       {frozen vegetables} -> {spaghetti} (conf: 0.292, supp: 0.028, lift: 1.679, conv: 1.167)\n",
       "8             {burgers} -> {mineral water} (conf: 0.280, supp: 0.024, lift: 1.174, conv: 1.058)\n",
       "9         {cooking oil} -> {mineral water} (conf: 0.394, supp: 0.020, lift: 1.654, conv: 1.257)\n",
       "10               {eggs} -> {mineral water} (conf: 0.283, supp: 0.051, lift: 1.189, conv: 1.063)\n",
       "11            {chicken} -> {mineral water} (conf: 0.380, supp: 0.023, lift: 1.594, conv: 1.228)\n",
       "12          {spaghetti} -> {mineral water} (conf: 0.343, supp: 0.060, lift: 1.439, conv: 1.159)\n",
       "13          {mineral water} -> {spaghetti} (conf: 0.251, supp: 0.060, lift: 1.439, conv: 1.102)\n",
       "14           {tomatoes} -> {mineral water} (conf: 0.357, supp: 0.024, lift: 1.497, conv: 1.184)\n",
       "15               {tomatoes} -> {spaghetti} (conf: 0.306, supp: 0.021, lift: 1.758, conv: 1.190)\n",
       "16           {pancakes} -> {mineral water} (conf: 0.355, supp: 0.034, lift: 1.489, conv: 1.181)\n",
       "17               {pancakes} -> {spaghetti} (conf: 0.265, supp: 0.025, lift: 1.522, conv: 1.124)\n",
       "18                   {milk} -> {spaghetti} (conf: 0.274, supp: 0.035, lift: 1.572, conv: 1.137)\n",
       "19        {ground beef} -> {mineral water} (conf: 0.417, supp: 0.041, lift: 1.748, conv: 1.305)\n",
       "20            {ground beef} -> {spaghetti} (conf: 0.399, supp: 0.039, lift: 2.291, conv: 1.374)\n",
       "21          {chocolate} -> {mineral water} (conf: 0.321, supp: 0.053, lift: 1.348, conv: 1.122)\n",
       "22  {frozen vegetables} -> {mineral water} (conf: 0.375, supp: 0.036, lift: 1.572, conv: 1.218)\n",
       "23               {cake} -> {mineral water} (conf: 0.339, supp: 0.027, lift: 1.421, conv: 1.152)\n",
       "24               {soup} -> {mineral water} (conf: 0.456, supp: 0.023, lift: 1.915, conv: 1.401)\n",
       "25              {olive oil} -> {spaghetti} (conf: 0.348, supp: 0.023, lift: 2.000, conv: 1.267)\n",
       "26             {burgers} -> {french fries} (conf: 0.252, supp: 0.022, lift: 1.476, conv: 1.109)\n",
       "27                 {shrimp} -> {spaghetti} (conf: 0.297, supp: 0.021, lift: 1.704, conv: 1.174)"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data1 = pd.DataFrame(rules,columns=['关联规则'])\n",
    "data1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 298,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过字符串拆分将关联规则列表str拆分成str和各指标数据，以方便查看及排序\n",
    "Association_rules_list,confidence_list,support_list,lift_list,conv_list = [],[],[],[],[]\n",
    "for key,value in data1['关联规则'].iteritems():\n",
    "#     print(str(value))\n",
    "    s = str(value)\n",
    "    conf_index = s.find('conf')\n",
    "    Association_rules = s[0:conf_index-2]\n",
    "    Association_rules_list.append(Association_rules)\n",
    "    \n",
    "    conf = float(s[conf_index+6:conf_index+11])\n",
    "    confidence_list.append(conf)\n",
    "    \n",
    "    support_index = s.find('supp')\n",
    "    supp = float(s[support_index+6:support_index+11])\n",
    "    support_list.append(supp)\n",
    "    \n",
    "    lift_index = s.find('lift')\n",
    "    lift =float(s[lift_index+6:lift_index+11])\n",
    "    lift_list.append(lift)\n",
    "    \n",
    "    conv_index = s.find('conv')\n",
    "    conv = float(s[conv_index+6:conv_index+11])\n",
    "    conv_list.append(conv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 311,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>关联规则</th>\n",
       "      <th>confidence</th>\n",
       "      <th>support</th>\n",
       "      <th>lift</th>\n",
       "      <th>conv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>{ground beef} -&gt; {spaghetti}</td>\n",
       "      <td>0.399</td>\n",
       "      <td>0.039</td>\n",
       "      <td>2.291</td>\n",
       "      <td>1.374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>{olive oil} -&gt; {spaghetti}</td>\n",
       "      <td>0.348</td>\n",
       "      <td>0.023</td>\n",
       "      <td>2.000</td>\n",
       "      <td>1.267</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>{soup} -&gt; {mineral water}</td>\n",
       "      <td>0.456</td>\n",
       "      <td>0.023</td>\n",
       "      <td>1.915</td>\n",
       "      <td>1.401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{burgers} -&gt; {eggs}</td>\n",
       "      <td>0.330</td>\n",
       "      <td>0.029</td>\n",
       "      <td>1.838</td>\n",
       "      <td>1.225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>{tomatoes} -&gt; {spaghetti}</td>\n",
       "      <td>0.306</td>\n",
       "      <td>0.021</td>\n",
       "      <td>1.758</td>\n",
       "      <td>1.190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{olive oil} -&gt; {mineral water}</td>\n",
       "      <td>0.419</td>\n",
       "      <td>0.028</td>\n",
       "      <td>1.758</td>\n",
       "      <td>1.311</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>{ground beef} -&gt; {mineral water}</td>\n",
       "      <td>0.417</td>\n",
       "      <td>0.041</td>\n",
       "      <td>1.748</td>\n",
       "      <td>1.305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>{shrimp} -&gt; {spaghetti}</td>\n",
       "      <td>0.297</td>\n",
       "      <td>0.021</td>\n",
       "      <td>1.704</td>\n",
       "      <td>1.174</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>{frozen vegetables} -&gt; {spaghetti}</td>\n",
       "      <td>0.292</td>\n",
       "      <td>0.028</td>\n",
       "      <td>1.679</td>\n",
       "      <td>1.167</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>{cooking oil} -&gt; {mineral water}</td>\n",
       "      <td>0.394</td>\n",
       "      <td>0.020</td>\n",
       "      <td>1.654</td>\n",
       "      <td>1.257</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>{chicken} -&gt; {mineral water}</td>\n",
       "      <td>0.380</td>\n",
       "      <td>0.023</td>\n",
       "      <td>1.594</td>\n",
       "      <td>1.228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>{frozen vegetables} -&gt; {mineral water}</td>\n",
       "      <td>0.375</td>\n",
       "      <td>0.036</td>\n",
       "      <td>1.572</td>\n",
       "      <td>1.218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>{milk} -&gt; {spaghetti}</td>\n",
       "      <td>0.274</td>\n",
       "      <td>0.035</td>\n",
       "      <td>1.572</td>\n",
       "      <td>1.137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>{milk} -&gt; {mineral water}</td>\n",
       "      <td>0.370</td>\n",
       "      <td>0.048</td>\n",
       "      <td>1.554</td>\n",
       "      <td>1.210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>{pancakes} -&gt; {spaghetti}</td>\n",
       "      <td>0.265</td>\n",
       "      <td>0.025</td>\n",
       "      <td>1.522</td>\n",
       "      <td>1.124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>{tomatoes} -&gt; {mineral water}</td>\n",
       "      <td>0.357</td>\n",
       "      <td>0.024</td>\n",
       "      <td>1.497</td>\n",
       "      <td>1.184</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>{pancakes} -&gt; {mineral water}</td>\n",
       "      <td>0.355</td>\n",
       "      <td>0.034</td>\n",
       "      <td>1.489</td>\n",
       "      <td>1.181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>{burgers} -&gt; {french fries}</td>\n",
       "      <td>0.252</td>\n",
       "      <td>0.022</td>\n",
       "      <td>1.476</td>\n",
       "      <td>1.109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>{whole wheat rice} -&gt; {mineral water}</td>\n",
       "      <td>0.344</td>\n",
       "      <td>0.020</td>\n",
       "      <td>1.443</td>\n",
       "      <td>1.161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>{mineral water} -&gt; {spaghetti}</td>\n",
       "      <td>0.251</td>\n",
       "      <td>0.060</td>\n",
       "      <td>1.439</td>\n",
       "      <td>1.102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>{spaghetti} -&gt; {mineral water}</td>\n",
       "      <td>0.343</td>\n",
       "      <td>0.060</td>\n",
       "      <td>1.439</td>\n",
       "      <td>1.159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>{cake} -&gt; {mineral water}</td>\n",
       "      <td>0.339</td>\n",
       "      <td>0.027</td>\n",
       "      <td>1.421</td>\n",
       "      <td>1.152</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{shrimp} -&gt; {mineral water}</td>\n",
       "      <td>0.330</td>\n",
       "      <td>0.024</td>\n",
       "      <td>1.385</td>\n",
       "      <td>1.137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>{chocolate} -&gt; {mineral water}</td>\n",
       "      <td>0.321</td>\n",
       "      <td>0.053</td>\n",
       "      <td>1.348</td>\n",
       "      <td>1.122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{frozen smoothie} -&gt; {mineral water}</td>\n",
       "      <td>0.320</td>\n",
       "      <td>0.020</td>\n",
       "      <td>1.342</td>\n",
       "      <td>1.120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{low fat yogurt} -&gt; {mineral water}</td>\n",
       "      <td>0.314</td>\n",
       "      <td>0.024</td>\n",
       "      <td>1.316</td>\n",
       "      <td>1.110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>{eggs} -&gt; {mineral water}</td>\n",
       "      <td>0.283</td>\n",
       "      <td>0.051</td>\n",
       "      <td>1.189</td>\n",
       "      <td>1.063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>{burgers} -&gt; {mineral water}</td>\n",
       "      <td>0.280</td>\n",
       "      <td>0.024</td>\n",
       "      <td>1.174</td>\n",
       "      <td>1.058</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      关联规则  confidence  support   lift   conv\n",
       "20            {ground beef} -> {spaghetti}       0.399    0.039  2.291  1.374\n",
       "25              {olive oil} -> {spaghetti}       0.348    0.023  2.000  1.267\n",
       "24               {soup} -> {mineral water}       0.456    0.023  1.915  1.401\n",
       "4                      {burgers} -> {eggs}       0.330    0.029  1.838  1.225\n",
       "15               {tomatoes} -> {spaghetti}       0.306    0.021  1.758  1.190\n",
       "2           {olive oil} -> {mineral water}       0.419    0.028  1.758  1.311\n",
       "19        {ground beef} -> {mineral water}       0.417    0.041  1.748  1.305\n",
       "27                 {shrimp} -> {spaghetti}       0.297    0.021  1.704  1.174\n",
       "7       {frozen vegetables} -> {spaghetti}       0.292    0.028  1.679  1.167\n",
       "9         {cooking oil} -> {mineral water}       0.394    0.020  1.654  1.257\n",
       "11            {chicken} -> {mineral water}       0.380    0.023  1.594  1.228\n",
       "22  {frozen vegetables} -> {mineral water}       0.375    0.036  1.572  1.218\n",
       "18                   {milk} -> {spaghetti}       0.274    0.035  1.572  1.137\n",
       "5                {milk} -> {mineral water}       0.370    0.048  1.554  1.210\n",
       "17               {pancakes} -> {spaghetti}       0.265    0.025  1.522  1.124\n",
       "14           {tomatoes} -> {mineral water}       0.357    0.024  1.497  1.184\n",
       "16           {pancakes} -> {mineral water}       0.355    0.034  1.489  1.181\n",
       "26             {burgers} -> {french fries}       0.252    0.022  1.476  1.109\n",
       "6    {whole wheat rice} -> {mineral water}       0.344    0.020  1.443  1.161\n",
       "13          {mineral water} -> {spaghetti}       0.251    0.060  1.439  1.102\n",
       "12          {spaghetti} -> {mineral water}       0.343    0.060  1.439  1.159\n",
       "23               {cake} -> {mineral water}       0.339    0.027  1.421  1.152\n",
       "3              {shrimp} -> {mineral water}       0.330    0.024  1.385  1.137\n",
       "21          {chocolate} -> {mineral water}       0.321    0.053  1.348  1.122\n",
       "0     {frozen smoothie} -> {mineral water}       0.320    0.020  1.342  1.120\n",
       "1      {low fat yogurt} -> {mineral water}       0.314    0.024  1.316  1.110\n",
       "10               {eggs} -> {mineral water}       0.283    0.051  1.189  1.063\n",
       "8             {burgers} -> {mineral water}       0.280    0.024  1.174  1.058"
      ]
     },
     "execution_count": 311,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rules = pd.DataFrame({'关联规则':Association_rules_list,'confidence':confidence_list,'support':support_list,'lift':lift_list,'conv':conv_list})\n",
    "rules = rules.sort_values(by=\"lift\" , ascending=False) \n",
    "rules"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 采用mlxtend.frequent_patterns工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [],
   "source": [
    "from mlxtend.frequent_patterns import apriori\n",
    "from mlxtend.frequent_patterns import association_rules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "      <th>12</th>\n",
       "      <th>13</th>\n",
       "      <th>14</th>\n",
       "      <th>15</th>\n",
       "      <th>16</th>\n",
       "      <th>17</th>\n",
       "      <th>18</th>\n",
       "      <th>19</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>shrimp</td>\n",
       "      <td>almonds</td>\n",
       "      <td>avocado</td>\n",
       "      <td>vegetables mix</td>\n",
       "      <td>green grapes</td>\n",
       "      <td>whole weat flour</td>\n",
       "      <td>yams</td>\n",
       "      <td>cottage cheese</td>\n",
       "      <td>energy drink</td>\n",
       "      <td>tomato juice</td>\n",
       "      <td>low fat yogurt</td>\n",
       "      <td>green tea</td>\n",
       "      <td>honey</td>\n",
       "      <td>salad</td>\n",
       "      <td>mineral water</td>\n",
       "      <td>salmon</td>\n",
       "      <td>antioxydant juice</td>\n",
       "      <td>frozen smoothie</td>\n",
       "      <td>spinach</td>\n",
       "      <td>olive oil</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>burgers</td>\n",
       "      <td>meatballs</td>\n",
       "      <td>eggs</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>chutney</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>turkey</td>\n",
       "      <td>avocado</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>mineral water</td>\n",
       "      <td>milk</td>\n",
       "      <td>energy bar</td>\n",
       "      <td>whole wheat rice</td>\n",
       "      <td>green tea</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              0          1           2                 3             4   \\\n",
       "0         shrimp    almonds     avocado    vegetables mix  green grapes   \n",
       "1        burgers  meatballs        eggs               NaN           NaN   \n",
       "2        chutney        NaN         NaN               NaN           NaN   \n",
       "3         turkey    avocado         NaN               NaN           NaN   \n",
       "4  mineral water       milk  energy bar  whole wheat rice     green tea   \n",
       "\n",
       "                 5     6               7             8             9   \\\n",
       "0  whole weat flour  yams  cottage cheese  energy drink  tomato juice   \n",
       "1               NaN   NaN             NaN           NaN           NaN   \n",
       "2               NaN   NaN             NaN           NaN           NaN   \n",
       "3               NaN   NaN             NaN           NaN           NaN   \n",
       "4               NaN   NaN             NaN           NaN           NaN   \n",
       "\n",
       "               10         11     12     13             14      15  \\\n",
       "0  low fat yogurt  green tea  honey  salad  mineral water  salmon   \n",
       "1             NaN        NaN    NaN    NaN            NaN     NaN   \n",
       "2             NaN        NaN    NaN    NaN            NaN     NaN   \n",
       "3             NaN        NaN    NaN    NaN            NaN     NaN   \n",
       "4             NaN        NaN    NaN    NaN            NaN     NaN   \n",
       "\n",
       "                  16               17       18         19  \n",
       "0  antioxydant juice  frozen smoothie  spinach  olive oil  \n",
       "1                NaN              NaN      NaN        NaN  \n",
       "2                NaN              NaN      NaN        NaN  \n",
       "3                NaN              NaN      NaN        NaN  \n",
       "4                NaN              NaN      NaN        NaN  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dataset.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据处理\n",
    "transactions2 = []\n",
    "for i in range(0,dataset.shape[0]):\n",
    "    temp = []\n",
    "    for j in range(0,dataset.shape[1]):\n",
    "        if str(dataset.values[i,j]) != 'nan':\n",
    "            temp.append(str(dataset.values[i,j]))\n",
    "    temp='|'.join(temp)        \n",
    "    # print(temp)\n",
    "    transactions2.append(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据处理后：\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Market_Basket</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>shrimp|almonds|avocado|vegetables mix|green grapes|whole weat flour|yams|cottage cheese|energy d...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>burgers|meatballs|eggs</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>chutney</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>turkey|avocado</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>mineral water|milk|energy bar|whole wheat rice|green tea</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>low fat yogurt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>whole wheat pasta|french fries</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>soup|light cream|shallot</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>frozen vegetables|spaghetti|green tea</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>french fries</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                                         Market_Basket\n",
       "0  shrimp|almonds|avocado|vegetables mix|green grapes|whole weat flour|yams|cottage cheese|energy d...\n",
       "1                                                                               burgers|meatballs|eggs\n",
       "2                                                                                              chutney\n",
       "3                                                                                       turkey|avocado\n",
       "4                                             mineral water|milk|energy bar|whole wheat rice|green tea\n",
       "5                                                                                       low fat yogurt\n",
       "6                                                                       whole wheat pasta|french fries\n",
       "7                                                                             soup|light cream|shallot\n",
       "8                                                                frozen vegetables|spaghetti|green tea\n",
       "9                                                                                         french fries"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_Market_Basket = pd.DataFrame(transactions2,columns=['Market_Basket'])\n",
    "print('数据处理后：')\n",
    "data_Market_Basket.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>asparagus</th>\n",
       "      <th>almonds</th>\n",
       "      <th>antioxydant juice</th>\n",
       "      <th>asparagus</th>\n",
       "      <th>avocado</th>\n",
       "      <th>babies food</th>\n",
       "      <th>bacon</th>\n",
       "      <th>barbecue sauce</th>\n",
       "      <th>black tea</th>\n",
       "      <th>blueberries</th>\n",
       "      <th>...</th>\n",
       "      <th>turkey</th>\n",
       "      <th>vegetables mix</th>\n",
       "      <th>water spray</th>\n",
       "      <th>white wine</th>\n",
       "      <th>whole weat flour</th>\n",
       "      <th>whole wheat pasta</th>\n",
       "      <th>whole wheat rice</th>\n",
       "      <th>yams</th>\n",
       "      <th>yogurt cake</th>\n",
       "      <th>zucchini</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 120 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    asparagus  almonds  antioxydant juice  asparagus  avocado  babies food  \\\n",
       "0           0        1                  1          0        1            0   \n",
       "1           0        0                  0          0        0            0   \n",
       "2           0        0                  0          0        0            0   \n",
       "3           0        0                  0          0        1            0   \n",
       "4           0        0                  0          0        0            0   \n",
       "\n",
       "   bacon  barbecue sauce  black tea  blueberries  ...  turkey  vegetables mix  \\\n",
       "0      0               0          0            0  ...       0               1   \n",
       "1      0               0          0            0  ...       0               0   \n",
       "2      0               0          0            0  ...       0               0   \n",
       "3      0               0          0            0  ...       1               0   \n",
       "4      0               0          0            0  ...       0               0   \n",
       "\n",
       "   water spray  white wine  whole weat flour  whole wheat pasta  \\\n",
       "0            0           0                 1                  0   \n",
       "1            0           0                 0                  0   \n",
       "2            0           0                 0                  0   \n",
       "3            0           0                 0                  0   \n",
       "4            0           0                 0                  0   \n",
       "\n",
       "   whole wheat rice  yams  yogurt cake  zucchini  \n",
       "0                 0     1            0         0  \n",
       "1                 0     0            0         0  \n",
       "2                 0     0            0         0  \n",
       "3                 0     0            0         0  \n",
       "4                 1     0            0         0  \n",
       "\n",
       "[5 rows x 120 columns]"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# one_hot编码\n",
    "hot_encoded = data_Market_Basket.drop('Market_Basket',1).join(data_Market_Basket.Market_Basket.str.get_dummies('|'))\n",
    "hot_encoded.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------- 频繁项集 ----------\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>support</th>\n",
       "      <th>itemsets</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>0.238368</td>\n",
       "      <td>(mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.179709</td>\n",
       "      <td>(eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>0.174110</td>\n",
       "      <td>(spaghetti)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.170911</td>\n",
       "      <td>(french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.163845</td>\n",
       "      <td>(chocolate)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.132116</td>\n",
       "      <td>(green tea)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>0.129583</td>\n",
       "      <td>(milk)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.098254</td>\n",
       "      <td>(ground beef)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.095321</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>0.095054</td>\n",
       "      <td>(pancakes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.087188</td>\n",
       "      <td>(burgers)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.081056</td>\n",
       "      <td>(cake)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.080389</td>\n",
       "      <td>(cookies)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.079323</td>\n",
       "      <td>(escalope)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>0.076523</td>\n",
       "      <td>(low fat yogurt)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>0.071457</td>\n",
       "      <td>(shrimp)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>0.068391</td>\n",
       "      <td>(tomatoes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>0.065858</td>\n",
       "      <td>(olive oil)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0.063325</td>\n",
       "      <td>(frozen smoothie)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>0.062525</td>\n",
       "      <td>(turkey)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.059992</td>\n",
       "      <td>(chicken)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>0.059725</td>\n",
       "      <td>(spaghetti, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>0.058526</td>\n",
       "      <td>(whole wheat rice)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>0.052660</td>\n",
       "      <td>(chocolate, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.052393</td>\n",
       "      <td>(grated cheese)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.051060</td>\n",
       "      <td>(cooking oil)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>0.050927</td>\n",
       "      <td>(mineral water, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>0.050527</td>\n",
       "      <td>(soup)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>0.049460</td>\n",
       "      <td>(herb &amp; pepper)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>0.047994</td>\n",
       "      <td>(milk, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.047460</td>\n",
       "      <td>(honey)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.046794</td>\n",
       "      <td>(champagne)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.043061</td>\n",
       "      <td>(fresh bread)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>0.042528</td>\n",
       "      <td>(salmon)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>0.040928</td>\n",
       "      <td>(ground beef, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>0.039195</td>\n",
       "      <td>(ground beef, spaghetti)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>0.039195</td>\n",
       "      <td>(chocolate, spaghetti)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>0.036528</td>\n",
       "      <td>(spaghetti, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>0.036395</td>\n",
       "      <td>(french fries, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>0.035729</td>\n",
       "      <td>(frozen vegetables, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>0.035462</td>\n",
       "      <td>(milk, spaghetti)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>0.034395</td>\n",
       "      <td>(chocolate, french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>0.033729</td>\n",
       "      <td>(mineral water, french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.033729</td>\n",
       "      <td>(brownies)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>0.033729</td>\n",
       "      <td>(mineral water, pancakes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.033329</td>\n",
       "      <td>(avocado)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>0.033196</td>\n",
       "      <td>(chocolate, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>0.032396</td>\n",
       "      <td>(hot dogs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>0.032129</td>\n",
       "      <td>(milk, chocolate)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.031862</td>\n",
       "      <td>(cottage cheese)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>0.031063</td>\n",
       "      <td>(green tea, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>0.030796</td>\n",
       "      <td>(milk, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>0.030396</td>\n",
       "      <td>(tomato juice)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.030129</td>\n",
       "      <td>(butter)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>0.029463</td>\n",
       "      <td>(whole wheat pasta)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>0.028796</td>\n",
       "      <td>(burgers, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>0.028530</td>\n",
       "      <td>(green tea, french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>0.028130</td>\n",
       "      <td>(red wine)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>0.027863</td>\n",
       "      <td>(spaghetti, frozen vegetables)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>0.027596</td>\n",
       "      <td>(spaghetti, french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>0.027596</td>\n",
       "      <td>(olive oil, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>0.027463</td>\n",
       "      <td>(mineral water, cake)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>0.027330</td>\n",
       "      <td>(yogurt cake)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>0.027196</td>\n",
       "      <td>(light mayo)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.027063</td>\n",
       "      <td>(energy bar)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.026663</td>\n",
       "      <td>(energy drink)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>0.026530</td>\n",
       "      <td>(pepper)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>0.026530</td>\n",
       "      <td>(ham)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>0.026530</td>\n",
       "      <td>(green tea, spaghetti)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>0.025730</td>\n",
       "      <td>(vegetables mix)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.025730</td>\n",
       "      <td>(cereals)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>0.025463</td>\n",
       "      <td>(green tea, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>100</th>\n",
       "      <td>0.025197</td>\n",
       "      <td>(spaghetti, pancakes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>0.024397</td>\n",
       "      <td>(burgers, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>0.024397</td>\n",
       "      <td>(mineral water, tomatoes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>0.024130</td>\n",
       "      <td>(muffins)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>0.023997</td>\n",
       "      <td>(low fat yogurt, mineral water)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>0.023730</td>\n",
       "      <td>(milk, french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>0.023597</td>\n",
       "      <td>(milk, frozen vegetables)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>0.023597</td>\n",
       "      <td>(mineral water, shrimp)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>0.023464</td>\n",
       "      <td>(green tea, chocolate)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>0.023064</td>\n",
       "      <td>(mineral water, soup)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>0.023064</td>\n",
       "      <td>(oil)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>0.023064</td>\n",
       "      <td>(ground beef, chocolate)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>0.022930</td>\n",
       "      <td>(olive oil, spaghetti)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>0.022930</td>\n",
       "      <td>(chocolate, frozen vegetables)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>0.022797</td>\n",
       "      <td>(mineral water, chicken)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.022530</td>\n",
       "      <td>(french wine)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.022264</td>\n",
       "      <td>(fresh tuna)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>0.021997</td>\n",
       "      <td>(milk, ground beef)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>0.021997</td>\n",
       "      <td>(burgers, french fries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>0.021730</td>\n",
       "      <td>(pancakes, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>0.021730</td>\n",
       "      <td>(frozen vegetables, eggs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>0.021464</td>\n",
       "      <td>(spaghetti, burgers)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>0.021330</td>\n",
       "      <td>(strawberries)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>0.021197</td>\n",
       "      <td>(spaghetti, shrimp)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>102</th>\n",
       "      <td>0.020931</td>\n",
       "      <td>(spaghetti, tomatoes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.020931</td>\n",
       "      <td>(meatballs)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.020397</td>\n",
       "      <td>(almonds)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>0.020264</td>\n",
       "      <td>(mineral water, frozen smoothie)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>0.020131</td>\n",
       "      <td>(mineral water, whole wheat rice)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>0.020131</td>\n",
       "      <td>(french fries, pancakes)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>0.020131</td>\n",
       "      <td>(mineral water, cooking oil)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      support                            itemsets\n",
       "34   0.238368                     (mineral water)\n",
       "13   0.179709                              (eggs)\n",
       "44   0.174110                         (spaghetti)\n",
       "17   0.170911                      (french fries)\n",
       "9    0.163845                         (chocolate)\n",
       "24   0.132116                         (green tea)\n",
       "33   0.129583                              (milk)\n",
       "25   0.098254                       (ground beef)\n",
       "22   0.095321                 (frozen vegetables)\n",
       "38   0.095054                          (pancakes)\n",
       "3    0.087188                           (burgers)\n",
       "5    0.081056                              (cake)\n",
       "10   0.080389                           (cookies)\n",
       "16   0.079323                          (escalope)\n",
       "31   0.076523                    (low fat yogurt)\n",
       "42   0.071457                            (shrimp)\n",
       "47   0.068391                          (tomatoes)\n",
       "37   0.065858                         (olive oil)\n",
       "21   0.063325                   (frozen smoothie)\n",
       "48   0.062525                            (turkey)\n",
       "8    0.059992                           (chicken)\n",
       "96   0.059725          (spaghetti, mineral water)\n",
       "51   0.058526                  (whole wheat rice)\n",
       "65   0.052660          (chocolate, mineral water)\n",
       "23   0.052393                     (grated cheese)\n",
       "11   0.051060                       (cooking oil)\n",
       "72   0.050927               (mineral water, eggs)\n",
       "43   0.050527                              (soup)\n",
       "27   0.049460                     (herb & pepper)\n",
       "90   0.047994               (milk, mineral water)\n",
       "28   0.047460                             (honey)\n",
       "7    0.046794                         (champagne)\n",
       "19   0.043061                       (fresh bread)\n",
       "41   0.042528                            (salmon)\n",
       "87   0.040928        (ground beef, mineral water)\n",
       "88   0.039195            (ground beef, spaghetti)\n",
       "66   0.039195              (chocolate, spaghetti)\n",
       "74   0.036528                   (spaghetti, eggs)\n",
       "68   0.036395                (french fries, eggs)\n",
       "82   0.035729  (frozen vegetables, mineral water)\n",
       "91   0.035462                   (milk, spaghetti)\n",
       "60   0.034395           (chocolate, french fries)\n",
       "77   0.033729       (mineral water, french fries)\n",
       "2    0.033729                          (brownies)\n",
       "93   0.033729           (mineral water, pancakes)\n",
       "1    0.033329                           (avocado)\n",
       "59   0.033196                   (chocolate, eggs)\n",
       "29   0.032396                          (hot dogs)\n",
       "64   0.032129                   (milk, chocolate)\n",
       "12   0.031862                    (cottage cheese)\n",
       "84   0.031063          (green tea, mineral water)\n",
       "71   0.030796                        (milk, eggs)\n",
       "46   0.030396                      (tomato juice)\n",
       "4    0.030129                            (butter)\n",
       "50   0.029463                 (whole wheat pasta)\n",
       "53   0.028796                     (burgers, eggs)\n",
       "75   0.028530           (green tea, french fries)\n",
       "40   0.028130                          (red wine)\n",
       "83   0.027863      (spaghetti, frozen vegetables)\n",
       "79   0.027596           (spaghetti, french fries)\n",
       "92   0.027596          (olive oil, mineral water)\n",
       "57   0.027463               (mineral water, cake)\n",
       "52   0.027330                       (yogurt cake)\n",
       "30   0.027196                        (light mayo)\n",
       "14   0.027063                        (energy bar)\n",
       "15   0.026663                      (energy drink)\n",
       "39   0.026530                            (pepper)\n",
       "26   0.026530                               (ham)\n",
       "85   0.026530              (green tea, spaghetti)\n",
       "49   0.025730                    (vegetables mix)\n",
       "6    0.025730                           (cereals)\n",
       "70   0.025463                   (green tea, eggs)\n",
       "100  0.025197               (spaghetti, pancakes)\n",
       "55   0.024397            (burgers, mineral water)\n",
       "97   0.024397           (mineral water, tomatoes)\n",
       "35   0.024130                           (muffins)\n",
       "89   0.023997     (low fat yogurt, mineral water)\n",
       "76   0.023730                (milk, french fries)\n",
       "81   0.023597           (milk, frozen vegetables)\n",
       "94   0.023597             (mineral water, shrimp)\n",
       "62   0.023464              (green tea, chocolate)\n",
       "95   0.023064               (mineral water, soup)\n",
       "36   0.023064                               (oil)\n",
       "63   0.023064            (ground beef, chocolate)\n",
       "99   0.022930              (olive oil, spaghetti)\n",
       "61   0.022930      (chocolate, frozen vegetables)\n",
       "58   0.022797            (mineral water, chicken)\n",
       "18   0.022530                       (french wine)\n",
       "20   0.022264                        (fresh tuna)\n",
       "86   0.021997                 (milk, ground beef)\n",
       "54   0.021997             (burgers, french fries)\n",
       "73   0.021730                    (pancakes, eggs)\n",
       "69   0.021730           (frozen vegetables, eggs)\n",
       "56   0.021464                (spaghetti, burgers)\n",
       "45   0.021330                      (strawberries)\n",
       "101  0.021197                 (spaghetti, shrimp)\n",
       "102  0.020931               (spaghetti, tomatoes)\n",
       "32   0.020931                         (meatballs)\n",
       "0    0.020397                           (almonds)\n",
       "80   0.020264    (mineral water, frozen smoothie)\n",
       "98   0.020131   (mineral water, whole wheat rice)\n",
       "78   0.020131            (french fries, pancakes)\n",
       "67   0.020131        (mineral water, cooking oil)"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 挖掘频繁项集，最小支持度为0.04\n",
    "itemsets2 = apriori(hot_encoded,use_colnames=True, min_support=0.02)\n",
    "# 按照支持度从大到小排序\n",
    "itemsets2 = itemsets2.sort_values(by=\"support\" , ascending=False) \n",
    "print('-'*10, '频繁项集', '-'*10)\n",
    "itemsets2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-------------------------------------- 关联规则 ----------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>antecedent support</th>\n",
       "      <th>consequent support</th>\n",
       "      <th>support</th>\n",
       "      <th>confidence</th>\n",
       "      <th>lift</th>\n",
       "      <th>leverage</th>\n",
       "      <th>conviction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.225115</td>\n",
       "      <td>2.291162</td>\n",
       "      <td>0.022088</td>\n",
       "      <td>1.163716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.398915</td>\n",
       "      <td>2.291162</td>\n",
       "      <td>0.022088</td>\n",
       "      <td>1.373997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.348178</td>\n",
       "      <td>1.999758</td>\n",
       "      <td>0.011464</td>\n",
       "      <td>1.267048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.131700</td>\n",
       "      <td>1.999758</td>\n",
       "      <td>0.011464</td>\n",
       "      <td>1.075829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(soup)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.050527</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.096756</td>\n",
       "      <td>1.914955</td>\n",
       "      <td>0.011020</td>\n",
       "      <td>1.051182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>63</th>\n",
       "      <td>(soup)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.050527</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.456464</td>\n",
       "      <td>1.914955</td>\n",
       "      <td>0.011020</td>\n",
       "      <td>1.401255</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.023597</td>\n",
       "      <td>0.182099</td>\n",
       "      <td>1.910382</td>\n",
       "      <td>0.011245</td>\n",
       "      <td>1.106099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>57</th>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.023597</td>\n",
       "      <td>0.247552</td>\n",
       "      <td>1.910382</td>\n",
       "      <td>0.011245</td>\n",
       "      <td>1.156781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.028796</td>\n",
       "      <td>0.160237</td>\n",
       "      <td>1.837830</td>\n",
       "      <td>0.013128</td>\n",
       "      <td>1.086988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>(burgers)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.028796</td>\n",
       "      <td>0.330275</td>\n",
       "      <td>1.837830</td>\n",
       "      <td>0.013128</td>\n",
       "      <td>1.224818</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.027596</td>\n",
       "      <td>0.419028</td>\n",
       "      <td>1.757904</td>\n",
       "      <td>0.011898</td>\n",
       "      <td>1.310962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.027596</td>\n",
       "      <td>0.115772</td>\n",
       "      <td>1.757904</td>\n",
       "      <td>0.011898</td>\n",
       "      <td>1.056449</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.068391</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.020931</td>\n",
       "      <td>0.306043</td>\n",
       "      <td>1.757755</td>\n",
       "      <td>0.009023</td>\n",
       "      <td>1.190117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.068391</td>\n",
       "      <td>0.020931</td>\n",
       "      <td>0.120214</td>\n",
       "      <td>1.757755</td>\n",
       "      <td>0.009023</td>\n",
       "      <td>1.058905</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.040928</td>\n",
       "      <td>0.171700</td>\n",
       "      <td>1.747522</td>\n",
       "      <td>0.017507</td>\n",
       "      <td>1.088672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.040928</td>\n",
       "      <td>0.416554</td>\n",
       "      <td>1.747522</td>\n",
       "      <td>0.017507</td>\n",
       "      <td>1.305401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.021997</td>\n",
       "      <td>0.223881</td>\n",
       "      <td>1.727704</td>\n",
       "      <td>0.009265</td>\n",
       "      <td>1.121499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.021997</td>\n",
       "      <td>0.169753</td>\n",
       "      <td>1.727704</td>\n",
       "      <td>0.009265</td>\n",
       "      <td>1.086118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.071457</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.021197</td>\n",
       "      <td>0.296642</td>\n",
       "      <td>1.703760</td>\n",
       "      <td>0.008756</td>\n",
       "      <td>1.174209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.071457</td>\n",
       "      <td>0.021197</td>\n",
       "      <td>0.121746</td>\n",
       "      <td>1.703760</td>\n",
       "      <td>0.008756</td>\n",
       "      <td>1.057260</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.027863</td>\n",
       "      <td>0.292308</td>\n",
       "      <td>1.678867</td>\n",
       "      <td>0.011267</td>\n",
       "      <td>1.167018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.027863</td>\n",
       "      <td>0.160031</td>\n",
       "      <td>1.678867</td>\n",
       "      <td>0.011267</td>\n",
       "      <td>1.077039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>(cooking oil)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.051060</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.394256</td>\n",
       "      <td>1.653978</td>\n",
       "      <td>0.007960</td>\n",
       "      <td>1.257349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(cooking oil)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.051060</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.084452</td>\n",
       "      <td>1.653978</td>\n",
       "      <td>0.007960</td>\n",
       "      <td>1.036472</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>(chicken)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.059992</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.022797</td>\n",
       "      <td>0.380000</td>\n",
       "      <td>1.594172</td>\n",
       "      <td>0.008497</td>\n",
       "      <td>1.228438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(chicken)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.059992</td>\n",
       "      <td>0.022797</td>\n",
       "      <td>0.095638</td>\n",
       "      <td>1.594172</td>\n",
       "      <td>0.008497</td>\n",
       "      <td>1.039415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.035729</td>\n",
       "      <td>0.149888</td>\n",
       "      <td>1.572463</td>\n",
       "      <td>0.013007</td>\n",
       "      <td>1.064189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.035729</td>\n",
       "      <td>0.374825</td>\n",
       "      <td>1.572463</td>\n",
       "      <td>0.013007</td>\n",
       "      <td>1.218270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.035462</td>\n",
       "      <td>0.203675</td>\n",
       "      <td>1.571779</td>\n",
       "      <td>0.012900</td>\n",
       "      <td>1.093043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.035462</td>\n",
       "      <td>0.273663</td>\n",
       "      <td>1.571779</td>\n",
       "      <td>0.012900</td>\n",
       "      <td>1.137061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.047994</td>\n",
       "      <td>0.201342</td>\n",
       "      <td>1.553774</td>\n",
       "      <td>0.017105</td>\n",
       "      <td>1.089850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.047994</td>\n",
       "      <td>0.370370</td>\n",
       "      <td>1.553774</td>\n",
       "      <td>0.017105</td>\n",
       "      <td>1.209650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.025197</td>\n",
       "      <td>0.144717</td>\n",
       "      <td>1.522468</td>\n",
       "      <td>0.008647</td>\n",
       "      <td>1.058066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.025197</td>\n",
       "      <td>0.265077</td>\n",
       "      <td>1.522468</td>\n",
       "      <td>0.008647</td>\n",
       "      <td>1.123778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.032129</td>\n",
       "      <td>0.196094</td>\n",
       "      <td>1.513276</td>\n",
       "      <td>0.010898</td>\n",
       "      <td>1.082736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.032129</td>\n",
       "      <td>0.247942</td>\n",
       "      <td>1.513276</td>\n",
       "      <td>0.010898</td>\n",
       "      <td>1.111823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.068391</td>\n",
       "      <td>0.024397</td>\n",
       "      <td>0.102349</td>\n",
       "      <td>1.496530</td>\n",
       "      <td>0.008095</td>\n",
       "      <td>1.037830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.068391</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.024397</td>\n",
       "      <td>0.356725</td>\n",
       "      <td>1.496530</td>\n",
       "      <td>0.008095</td>\n",
       "      <td>1.183991</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.033729</td>\n",
       "      <td>0.141499</td>\n",
       "      <td>1.488616</td>\n",
       "      <td>0.011071</td>\n",
       "      <td>1.054100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.033729</td>\n",
       "      <td>0.354839</td>\n",
       "      <td>1.488616</td>\n",
       "      <td>0.011071</td>\n",
       "      <td>1.180529</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.021997</td>\n",
       "      <td>0.128705</td>\n",
       "      <td>1.476173</td>\n",
       "      <td>0.007096</td>\n",
       "      <td>1.047650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>(burgers)</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.021997</td>\n",
       "      <td>0.252294</td>\n",
       "      <td>1.476173</td>\n",
       "      <td>0.007096</td>\n",
       "      <td>1.108844</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.139951</td>\n",
       "      <td>1.468215</td>\n",
       "      <td>0.007312</td>\n",
       "      <td>1.051893</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.240559</td>\n",
       "      <td>1.468215</td>\n",
       "      <td>0.007312</td>\n",
       "      <td>1.101015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>(whole wheat rice)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.058526</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.343964</td>\n",
       "      <td>1.442993</td>\n",
       "      <td>0.006180</td>\n",
       "      <td>1.160960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(whole wheat rice)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.058526</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.084452</td>\n",
       "      <td>1.442993</td>\n",
       "      <td>0.006180</td>\n",
       "      <td>1.028318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.059725</td>\n",
       "      <td>0.343032</td>\n",
       "      <td>1.439085</td>\n",
       "      <td>0.018223</td>\n",
       "      <td>1.159314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.059725</td>\n",
       "      <td>0.250559</td>\n",
       "      <td>1.439085</td>\n",
       "      <td>0.018223</td>\n",
       "      <td>1.102008</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.140765</td>\n",
       "      <td>1.432669</td>\n",
       "      <td>0.006965</td>\n",
       "      <td>1.049476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>64</th>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.234735</td>\n",
       "      <td>1.432669</td>\n",
       "      <td>0.006965</td>\n",
       "      <td>1.092635</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>(cake)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.081056</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.027463</td>\n",
       "      <td>0.338816</td>\n",
       "      <td>1.421397</td>\n",
       "      <td>0.008142</td>\n",
       "      <td>1.151921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(cake)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.081056</td>\n",
       "      <td>0.027463</td>\n",
       "      <td>0.115213</td>\n",
       "      <td>1.421397</td>\n",
       "      <td>0.008142</td>\n",
       "      <td>1.038604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.021464</td>\n",
       "      <td>0.123277</td>\n",
       "      <td>1.413918</td>\n",
       "      <td>0.006283</td>\n",
       "      <td>1.041163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>(burgers)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.021464</td>\n",
       "      <td>0.246177</td>\n",
       "      <td>1.413918</td>\n",
       "      <td>0.006283</td>\n",
       "      <td>1.095602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.071457</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.023597</td>\n",
       "      <td>0.330224</td>\n",
       "      <td>1.385352</td>\n",
       "      <td>0.006564</td>\n",
       "      <td>1.137144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.071457</td>\n",
       "      <td>0.023597</td>\n",
       "      <td>0.098993</td>\n",
       "      <td>1.385352</td>\n",
       "      <td>0.006564</td>\n",
       "      <td>1.030562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.225115</td>\n",
       "      <td>1.373952</td>\n",
       "      <td>0.010668</td>\n",
       "      <td>1.079070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.239219</td>\n",
       "      <td>1.373952</td>\n",
       "      <td>0.010668</td>\n",
       "      <td>1.085581</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.052660</td>\n",
       "      <td>0.321400</td>\n",
       "      <td>1.348332</td>\n",
       "      <td>0.013604</td>\n",
       "      <td>1.122357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.052660</td>\n",
       "      <td>0.220917</td>\n",
       "      <td>1.348332</td>\n",
       "      <td>0.013604</td>\n",
       "      <td>1.073256</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>(frozen smoothie)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.063325</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.020264</td>\n",
       "      <td>0.320000</td>\n",
       "      <td>1.342461</td>\n",
       "      <td>0.005169</td>\n",
       "      <td>1.120047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(frozen smoothie)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.063325</td>\n",
       "      <td>0.020264</td>\n",
       "      <td>0.085011</td>\n",
       "      <td>1.342461</td>\n",
       "      <td>0.005169</td>\n",
       "      <td>1.023701</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.030796</td>\n",
       "      <td>0.237654</td>\n",
       "      <td>1.322437</td>\n",
       "      <td>0.007509</td>\n",
       "      <td>1.076009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.030796</td>\n",
       "      <td>0.171365</td>\n",
       "      <td>1.322437</td>\n",
       "      <td>0.007509</td>\n",
       "      <td>1.050423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52</th>\n",
       "      <td>(low fat yogurt)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.076523</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.023997</td>\n",
       "      <td>0.313589</td>\n",
       "      <td>1.315565</td>\n",
       "      <td>0.005756</td>\n",
       "      <td>1.109585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>53</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(low fat yogurt)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.076523</td>\n",
       "      <td>0.023997</td>\n",
       "      <td>0.100671</td>\n",
       "      <td>1.315565</td>\n",
       "      <td>0.005756</td>\n",
       "      <td>1.026851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.021730</td>\n",
       "      <td>0.228612</td>\n",
       "      <td>1.272118</td>\n",
       "      <td>0.004648</td>\n",
       "      <td>1.063395</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.021730</td>\n",
       "      <td>0.120920</td>\n",
       "      <td>1.272118</td>\n",
       "      <td>0.004648</td>\n",
       "      <td>1.029424</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.021730</td>\n",
       "      <td>0.120920</td>\n",
       "      <td>1.268559</td>\n",
       "      <td>0.004600</td>\n",
       "      <td>1.029121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.021730</td>\n",
       "      <td>0.227972</td>\n",
       "      <td>1.268559</td>\n",
       "      <td>0.004600</td>\n",
       "      <td>1.062514</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>(green tea)</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.028530</td>\n",
       "      <td>0.215943</td>\n",
       "      <td>1.263488</td>\n",
       "      <td>0.005950</td>\n",
       "      <td>1.057436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(green tea)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.028530</td>\n",
       "      <td>0.166927</td>\n",
       "      <td>1.263488</td>\n",
       "      <td>0.005950</td>\n",
       "      <td>1.041786</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.117785</td>\n",
       "      <td>1.239135</td>\n",
       "      <td>0.003885</td>\n",
       "      <td>1.025766</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.211781</td>\n",
       "      <td>1.239135</td>\n",
       "      <td>0.003885</td>\n",
       "      <td>1.051852</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.034395</td>\n",
       "      <td>0.209927</td>\n",
       "      <td>1.228284</td>\n",
       "      <td>0.006393</td>\n",
       "      <td>1.049383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.034395</td>\n",
       "      <td>0.201248</td>\n",
       "      <td>1.228284</td>\n",
       "      <td>0.006393</td>\n",
       "      <td>1.046827</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.050927</td>\n",
       "      <td>0.283383</td>\n",
       "      <td>1.188845</td>\n",
       "      <td>0.008090</td>\n",
       "      <td>1.062815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.050927</td>\n",
       "      <td>0.213647</td>\n",
       "      <td>1.188845</td>\n",
       "      <td>0.008090</td>\n",
       "      <td>1.043158</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.036395</td>\n",
       "      <td>0.202522</td>\n",
       "      <td>1.184961</td>\n",
       "      <td>0.005681</td>\n",
       "      <td>1.039640</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.036395</td>\n",
       "      <td>0.212949</td>\n",
       "      <td>1.184961</td>\n",
       "      <td>0.005681</td>\n",
       "      <td>1.042232</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>(burgers)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.024397</td>\n",
       "      <td>0.279817</td>\n",
       "      <td>1.173883</td>\n",
       "      <td>0.003614</td>\n",
       "      <td>1.057552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.024397</td>\n",
       "      <td>0.102349</td>\n",
       "      <td>1.173883</td>\n",
       "      <td>0.003614</td>\n",
       "      <td>1.016889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.036528</td>\n",
       "      <td>0.203264</td>\n",
       "      <td>1.167446</td>\n",
       "      <td>0.005239</td>\n",
       "      <td>1.036592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.036528</td>\n",
       "      <td>0.209801</td>\n",
       "      <td>1.167446</td>\n",
       "      <td>0.005239</td>\n",
       "      <td>1.038081</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>(green tea)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.026530</td>\n",
       "      <td>0.200807</td>\n",
       "      <td>1.153335</td>\n",
       "      <td>0.003527</td>\n",
       "      <td>1.033405</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(green tea)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.026530</td>\n",
       "      <td>0.152374</td>\n",
       "      <td>1.153335</td>\n",
       "      <td>0.003527</td>\n",
       "      <td>1.023900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.033196</td>\n",
       "      <td>0.184718</td>\n",
       "      <td>1.127397</td>\n",
       "      <td>0.003751</td>\n",
       "      <td>1.025603</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.033196</td>\n",
       "      <td>0.202604</td>\n",
       "      <td>1.127397</td>\n",
       "      <td>0.003751</td>\n",
       "      <td>1.028711</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(green tea)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.023464</td>\n",
       "      <td>0.143206</td>\n",
       "      <td>1.083943</td>\n",
       "      <td>0.001817</td>\n",
       "      <td>1.012944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>60</th>\n",
       "      <td>(green tea)</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.023464</td>\n",
       "      <td>0.177598</td>\n",
       "      <td>1.083943</td>\n",
       "      <td>0.001817</td>\n",
       "      <td>1.016724</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(green tea)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.025463</td>\n",
       "      <td>0.141691</td>\n",
       "      <td>1.072479</td>\n",
       "      <td>0.001721</td>\n",
       "      <td>1.011156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>(green tea)</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>0.132116</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.025463</td>\n",
       "      <td>0.192735</td>\n",
       "      <td>1.072479</td>\n",
       "      <td>0.001721</td>\n",
       "      <td>1.016135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.023730</td>\n",
       "      <td>0.138846</td>\n",
       "      <td>1.071482</td>\n",
       "      <td>0.001583</td>\n",
       "      <td>1.010756</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.023730</td>\n",
       "      <td>0.183128</td>\n",
       "      <td>1.071482</td>\n",
       "      <td>0.001583</td>\n",
       "      <td>1.014956</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            antecedents          consequents  antecedent support  \\\n",
       "11          (spaghetti)        (ground beef)            0.174110   \n",
       "10        (ground beef)          (spaghetti)            0.098254   \n",
       "66          (olive oil)          (spaghetti)            0.065858   \n",
       "67          (spaghetti)          (olive oil)            0.174110   \n",
       "62      (mineral water)               (soup)            0.238368   \n",
       "63               (soup)      (mineral water)            0.050527   \n",
       "56               (milk)  (frozen vegetables)            0.129583   \n",
       "57  (frozen vegetables)               (milk)            0.095321   \n",
       "33               (eggs)            (burgers)            0.179709   \n",
       "32            (burgers)               (eggs)            0.087188   \n",
       "38          (olive oil)      (mineral water)            0.065858   \n",
       "39      (mineral water)          (olive oil)            0.238368   \n",
       "85           (tomatoes)          (spaghetti)            0.068391   \n",
       "84          (spaghetti)           (tomatoes)            0.174110   \n",
       "9       (mineral water)        (ground beef)            0.238368   \n",
       "8         (ground beef)      (mineral water)            0.098254   \n",
       "73        (ground beef)               (milk)            0.098254   \n",
       "72               (milk)        (ground beef)            0.129583   \n",
       "83             (shrimp)          (spaghetti)            0.071457   \n",
       "82          (spaghetti)             (shrimp)            0.174110   \n",
       "37  (frozen vegetables)          (spaghetti)            0.095321   \n",
       "36          (spaghetti)  (frozen vegetables)            0.174110   \n",
       "93        (cooking oil)      (mineral water)            0.051060   \n",
       "92      (mineral water)        (cooking oil)            0.238368   \n",
       "71            (chicken)      (mineral water)            0.059992   \n",
       "70      (mineral water)            (chicken)            0.238368   \n",
       "19      (mineral water)  (frozen vegetables)            0.238368   \n",
       "18  (frozen vegetables)      (mineral water)            0.095321   \n",
       "21          (spaghetti)               (milk)            0.174110   \n",
       "20               (milk)          (spaghetti)            0.129583   \n",
       "7       (mineral water)               (milk)            0.238368   \n",
       "6                (milk)      (mineral water)            0.129583   \n",
       "46          (spaghetti)           (pancakes)            0.174110   \n",
       "47           (pancakes)          (spaghetti)            0.095054   \n",
       "29          (chocolate)               (milk)            0.163845   \n",
       "28               (milk)          (chocolate)            0.129583   \n",
       "50      (mineral water)           (tomatoes)            0.238368   \n",
       "51           (tomatoes)      (mineral water)            0.068391   \n",
       "24      (mineral water)           (pancakes)            0.238368   \n",
       "25           (pancakes)      (mineral water)            0.095054   \n",
       "75       (french fries)            (burgers)            0.170911   \n",
       "74            (burgers)       (french fries)            0.087188   \n",
       "68          (chocolate)  (frozen vegetables)            0.163845   \n",
       "69  (frozen vegetables)          (chocolate)            0.095321   \n",
       "89   (whole wheat rice)      (mineral water)            0.058526   \n",
       "88      (mineral water)   (whole wheat rice)            0.238368   \n",
       "0           (spaghetti)      (mineral water)            0.174110   \n",
       "1       (mineral water)          (spaghetti)            0.238368   \n",
       "65          (chocolate)        (ground beef)            0.163845   \n",
       "64        (ground beef)          (chocolate)            0.098254   \n",
       "41               (cake)      (mineral water)            0.081056   \n",
       "40      (mineral water)               (cake)            0.238368   \n",
       "80          (spaghetti)            (burgers)            0.174110   \n",
       "81            (burgers)          (spaghetti)            0.087188   \n",
       "59             (shrimp)      (mineral water)            0.071457   \n",
       "58      (mineral water)             (shrimp)            0.238368   \n",
       "13          (spaghetti)          (chocolate)            0.174110   \n",
       "12          (chocolate)          (spaghetti)            0.163845   \n",
       "2           (chocolate)      (mineral water)            0.163845   \n",
       "3       (mineral water)          (chocolate)            0.238368   \n",
       "87    (frozen smoothie)      (mineral water)            0.063325   \n",
       "86      (mineral water)    (frozen smoothie)            0.238368   \n",
       "30               (milk)               (eggs)            0.129583   \n",
       "31               (eggs)               (milk)            0.179709   \n",
       "52     (low fat yogurt)      (mineral water)            0.076523   \n",
       "53      (mineral water)     (low fat yogurt)            0.238368   \n",
       "76           (pancakes)               (eggs)            0.095054   \n",
       "77               (eggs)           (pancakes)            0.179709   \n",
       "79               (eggs)  (frozen vegetables)            0.179709   \n",
       "78  (frozen vegetables)               (eggs)            0.095321   \n",
       "34          (green tea)       (french fries)            0.132116   \n",
       "35       (french fries)          (green tea)            0.170911   \n",
       "90       (french fries)           (pancakes)            0.170911   \n",
       "91           (pancakes)       (french fries)            0.095054   \n",
       "22          (chocolate)       (french fries)            0.163845   \n",
       "23       (french fries)          (chocolate)            0.170911   \n",
       "5                (eggs)      (mineral water)            0.179709   \n",
       "4       (mineral water)               (eggs)            0.238368   \n",
       "17               (eggs)       (french fries)            0.179709   \n",
       "16       (french fries)               (eggs)            0.170911   \n",
       "48            (burgers)      (mineral water)            0.087188   \n",
       "49      (mineral water)            (burgers)            0.238368   \n",
       "15               (eggs)          (spaghetti)            0.179709   \n",
       "14          (spaghetti)               (eggs)            0.174110   \n",
       "42          (green tea)          (spaghetti)            0.132116   \n",
       "43          (spaghetti)          (green tea)            0.174110   \n",
       "27               (eggs)          (chocolate)            0.179709   \n",
       "26          (chocolate)               (eggs)            0.163845   \n",
       "61          (chocolate)          (green tea)            0.163845   \n",
       "60          (green tea)          (chocolate)            0.132116   \n",
       "45               (eggs)          (green tea)            0.179709   \n",
       "44          (green tea)               (eggs)            0.132116   \n",
       "55       (french fries)               (milk)            0.170911   \n",
       "54               (milk)       (french fries)            0.129583   \n",
       "\n",
       "    consequent support   support  confidence      lift  leverage  conviction  \n",
       "11            0.098254  0.039195    0.225115  2.291162  0.022088    1.163716  \n",
       "10            0.174110  0.039195    0.398915  2.291162  0.022088    1.373997  \n",
       "66            0.174110  0.022930    0.348178  1.999758  0.011464    1.267048  \n",
       "67            0.065858  0.022930    0.131700  1.999758  0.011464    1.075829  \n",
       "62            0.050527  0.023064    0.096756  1.914955  0.011020    1.051182  \n",
       "63            0.238368  0.023064    0.456464  1.914955  0.011020    1.401255  \n",
       "56            0.095321  0.023597    0.182099  1.910382  0.011245    1.106099  \n",
       "57            0.129583  0.023597    0.247552  1.910382  0.011245    1.156781  \n",
       "33            0.087188  0.028796    0.160237  1.837830  0.013128    1.086988  \n",
       "32            0.179709  0.028796    0.330275  1.837830  0.013128    1.224818  \n",
       "38            0.238368  0.027596    0.419028  1.757904  0.011898    1.310962  \n",
       "39            0.065858  0.027596    0.115772  1.757904  0.011898    1.056449  \n",
       "85            0.174110  0.020931    0.306043  1.757755  0.009023    1.190117  \n",
       "84            0.068391  0.020931    0.120214  1.757755  0.009023    1.058905  \n",
       "9             0.098254  0.040928    0.171700  1.747522  0.017507    1.088672  \n",
       "8             0.238368  0.040928    0.416554  1.747522  0.017507    1.305401  \n",
       "73            0.129583  0.021997    0.223881  1.727704  0.009265    1.121499  \n",
       "72            0.098254  0.021997    0.169753  1.727704  0.009265    1.086118  \n",
       "83            0.174110  0.021197    0.296642  1.703760  0.008756    1.174209  \n",
       "82            0.071457  0.021197    0.121746  1.703760  0.008756    1.057260  \n",
       "37            0.174110  0.027863    0.292308  1.678867  0.011267    1.167018  \n",
       "36            0.095321  0.027863    0.160031  1.678867  0.011267    1.077039  \n",
       "93            0.238368  0.020131    0.394256  1.653978  0.007960    1.257349  \n",
       "92            0.051060  0.020131    0.084452  1.653978  0.007960    1.036472  \n",
       "71            0.238368  0.022797    0.380000  1.594172  0.008497    1.228438  \n",
       "70            0.059992  0.022797    0.095638  1.594172  0.008497    1.039415  \n",
       "19            0.095321  0.035729    0.149888  1.572463  0.013007    1.064189  \n",
       "18            0.238368  0.035729    0.374825  1.572463  0.013007    1.218270  \n",
       "21            0.129583  0.035462    0.203675  1.571779  0.012900    1.093043  \n",
       "20            0.174110  0.035462    0.273663  1.571779  0.012900    1.137061  \n",
       "7             0.129583  0.047994    0.201342  1.553774  0.017105    1.089850  \n",
       "6             0.238368  0.047994    0.370370  1.553774  0.017105    1.209650  \n",
       "46            0.095054  0.025197    0.144717  1.522468  0.008647    1.058066  \n",
       "47            0.174110  0.025197    0.265077  1.522468  0.008647    1.123778  \n",
       "29            0.129583  0.032129    0.196094  1.513276  0.010898    1.082736  \n",
       "28            0.163845  0.032129    0.247942  1.513276  0.010898    1.111823  \n",
       "50            0.068391  0.024397    0.102349  1.496530  0.008095    1.037830  \n",
       "51            0.238368  0.024397    0.356725  1.496530  0.008095    1.183991  \n",
       "24            0.095054  0.033729    0.141499  1.488616  0.011071    1.054100  \n",
       "25            0.238368  0.033729    0.354839  1.488616  0.011071    1.180529  \n",
       "75            0.087188  0.021997    0.128705  1.476173  0.007096    1.047650  \n",
       "74            0.170911  0.021997    0.252294  1.476173  0.007096    1.108844  \n",
       "68            0.095321  0.022930    0.139951  1.468215  0.007312    1.051893  \n",
       "69            0.163845  0.022930    0.240559  1.468215  0.007312    1.101015  \n",
       "89            0.238368  0.020131    0.343964  1.442993  0.006180    1.160960  \n",
       "88            0.058526  0.020131    0.084452  1.442993  0.006180    1.028318  \n",
       "0             0.238368  0.059725    0.343032  1.439085  0.018223    1.159314  \n",
       "1             0.174110  0.059725    0.250559  1.439085  0.018223    1.102008  \n",
       "65            0.098254  0.023064    0.140765  1.432669  0.006965    1.049476  \n",
       "64            0.163845  0.023064    0.234735  1.432669  0.006965    1.092635  \n",
       "41            0.238368  0.027463    0.338816  1.421397  0.008142    1.151921  \n",
       "40            0.081056  0.027463    0.115213  1.421397  0.008142    1.038604  \n",
       "80            0.087188  0.021464    0.123277  1.413918  0.006283    1.041163  \n",
       "81            0.174110  0.021464    0.246177  1.413918  0.006283    1.095602  \n",
       "59            0.238368  0.023597    0.330224  1.385352  0.006564    1.137144  \n",
       "58            0.071457  0.023597    0.098993  1.385352  0.006564    1.030562  \n",
       "13            0.163845  0.039195    0.225115  1.373952  0.010668    1.079070  \n",
       "12            0.174110  0.039195    0.239219  1.373952  0.010668    1.085581  \n",
       "2             0.238368  0.052660    0.321400  1.348332  0.013604    1.122357  \n",
       "3             0.163845  0.052660    0.220917  1.348332  0.013604    1.073256  \n",
       "87            0.238368  0.020264    0.320000  1.342461  0.005169    1.120047  \n",
       "86            0.063325  0.020264    0.085011  1.342461  0.005169    1.023701  \n",
       "30            0.179709  0.030796    0.237654  1.322437  0.007509    1.076009  \n",
       "31            0.129583  0.030796    0.171365  1.322437  0.007509    1.050423  \n",
       "52            0.238368  0.023997    0.313589  1.315565  0.005756    1.109585  \n",
       "53            0.076523  0.023997    0.100671  1.315565  0.005756    1.026851  \n",
       "76            0.179709  0.021730    0.228612  1.272118  0.004648    1.063395  \n",
       "77            0.095054  0.021730    0.120920  1.272118  0.004648    1.029424  \n",
       "79            0.095321  0.021730    0.120920  1.268559  0.004600    1.029121  \n",
       "78            0.179709  0.021730    0.227972  1.268559  0.004600    1.062514  \n",
       "34            0.170911  0.028530    0.215943  1.263488  0.005950    1.057436  \n",
       "35            0.132116  0.028530    0.166927  1.263488  0.005950    1.041786  \n",
       "90            0.095054  0.020131    0.117785  1.239135  0.003885    1.025766  \n",
       "91            0.170911  0.020131    0.211781  1.239135  0.003885    1.051852  \n",
       "22            0.170911  0.034395    0.209927  1.228284  0.006393    1.049383  \n",
       "23            0.163845  0.034395    0.201248  1.228284  0.006393    1.046827  \n",
       "5             0.238368  0.050927    0.283383  1.188845  0.008090    1.062815  \n",
       "4             0.179709  0.050927    0.213647  1.188845  0.008090    1.043158  \n",
       "17            0.170911  0.036395    0.202522  1.184961  0.005681    1.039640  \n",
       "16            0.179709  0.036395    0.212949  1.184961  0.005681    1.042232  \n",
       "48            0.238368  0.024397    0.279817  1.173883  0.003614    1.057552  \n",
       "49            0.087188  0.024397    0.102349  1.173883  0.003614    1.016889  \n",
       "15            0.174110  0.036528    0.203264  1.167446  0.005239    1.036592  \n",
       "14            0.179709  0.036528    0.209801  1.167446  0.005239    1.038081  \n",
       "42            0.174110  0.026530    0.200807  1.153335  0.003527    1.033405  \n",
       "43            0.132116  0.026530    0.152374  1.153335  0.003527    1.023900  \n",
       "27            0.163845  0.033196    0.184718  1.127397  0.003751    1.025603  \n",
       "26            0.179709  0.033196    0.202604  1.127397  0.003751    1.028711  \n",
       "61            0.132116  0.023464    0.143206  1.083943  0.001817    1.012944  \n",
       "60            0.163845  0.023464    0.177598  1.083943  0.001817    1.016724  \n",
       "45            0.132116  0.025463    0.141691  1.072479  0.001721    1.011156  \n",
       "44            0.179709  0.025463    0.192735  1.072479  0.001721    1.016135  \n",
       "55            0.129583  0.023730    0.138846  1.071482  0.001583    1.010756  \n",
       "54            0.170911  0.023730    0.183128  1.071482  0.001583    1.014956  "
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据频繁项集计算关联规则\n",
    "rules2 =  association_rules(itemsets2, metric='lift',min_threshold=1)\n",
    "# 按照提升度从大到小进行排序\n",
    "rules2 = rules2.sort_values(by=\"lift\" , ascending=False) \n",
    "print('-'*38, '关联规则', '-'*40)\n",
    "rules2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 两种工具结果对比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 337,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>关联规则</th>\n",
       "      <th>confidence</th>\n",
       "      <th>support</th>\n",
       "      <th>lift</th>\n",
       "      <th>conv</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>{ground beef} -&gt; {spaghetti}</td>\n",
       "      <td>0.399</td>\n",
       "      <td>0.039</td>\n",
       "      <td>2.291</td>\n",
       "      <td>1.374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>{olive oil} -&gt; {spaghetti}</td>\n",
       "      <td>0.348</td>\n",
       "      <td>0.023</td>\n",
       "      <td>2.000</td>\n",
       "      <td>1.267</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>{soup} -&gt; {mineral water}</td>\n",
       "      <td>0.456</td>\n",
       "      <td>0.023</td>\n",
       "      <td>1.915</td>\n",
       "      <td>1.401</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{burgers} -&gt; {eggs}</td>\n",
       "      <td>0.330</td>\n",
       "      <td>0.029</td>\n",
       "      <td>1.838</td>\n",
       "      <td>1.225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>{tomatoes} -&gt; {spaghetti}</td>\n",
       "      <td>0.306</td>\n",
       "      <td>0.021</td>\n",
       "      <td>1.758</td>\n",
       "      <td>1.190</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                            关联规则  confidence  support   lift   conv\n",
       "20  {ground beef} -> {spaghetti}       0.399    0.039  2.291  1.374\n",
       "25    {olive oil} -> {spaghetti}       0.348    0.023  2.000  1.267\n",
       "24     {soup} -> {mineral water}       0.456    0.023  1.915  1.401\n",
       "4            {burgers} -> {eggs}       0.330    0.029  1.838  1.225\n",
       "15     {tomatoes} -> {spaghetti}       0.306    0.021  1.758  1.190"
      ]
     },
     "execution_count": 337,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rules.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 390,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>antecedent support</th>\n",
       "      <th>consequent support</th>\n",
       "      <th>support</th>\n",
       "      <th>confidence</th>\n",
       "      <th>lift</th>\n",
       "      <th>leverage</th>\n",
       "      <th>conviction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.225115</td>\n",
       "      <td>2.291162</td>\n",
       "      <td>0.022088</td>\n",
       "      <td>1.163716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.398915</td>\n",
       "      <td>2.291162</td>\n",
       "      <td>0.022088</td>\n",
       "      <td>1.373997</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.348178</td>\n",
       "      <td>1.999758</td>\n",
       "      <td>0.011464</td>\n",
       "      <td>1.267048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>67</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.131700</td>\n",
       "      <td>1.999758</td>\n",
       "      <td>0.011464</td>\n",
       "      <td>1.075829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(soup)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.050527</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.096756</td>\n",
       "      <td>1.914955</td>\n",
       "      <td>0.011020</td>\n",
       "      <td>1.051182</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        antecedents    consequents  antecedent support  consequent support  \\\n",
       "11      (spaghetti)  (ground beef)            0.174110            0.098254   \n",
       "10    (ground beef)    (spaghetti)            0.098254            0.174110   \n",
       "66      (olive oil)    (spaghetti)            0.065858            0.174110   \n",
       "67      (spaghetti)    (olive oil)            0.174110            0.065858   \n",
       "62  (mineral water)         (soup)            0.238368            0.050527   \n",
       "\n",
       "     support  confidence      lift  leverage  conviction  \n",
       "11  0.039195    0.225115  2.291162  0.022088    1.163716  \n",
       "10  0.039195    0.398915  2.291162  0.022088    1.373997  \n",
       "66  0.022930    0.348178  1.999758  0.011464    1.267048  \n",
       "67  0.022930    0.131700  1.999758  0.011464    1.075829  \n",
       "62  0.023064    0.096756  1.914955  0.011020    1.051182  "
      ]
     },
     "execution_count": 390,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rules2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 396,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 避免两个表重复columns\n",
    "rules = rules.rename(columns = {'lift':'lift1'}) \n",
    "rules2 = rules2.rename(columns = {'lift':'lift2'}) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 397,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>antecedent support</th>\n",
       "      <th>consequent support</th>\n",
       "      <th>support</th>\n",
       "      <th>confidence</th>\n",
       "      <th>lift2</th>\n",
       "      <th>leverage</th>\n",
       "      <th>conviction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.039195</td>\n",
       "      <td>0.225115</td>\n",
       "      <td>2.291162</td>\n",
       "      <td>0.022088</td>\n",
       "      <td>1.163716</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.348178</td>\n",
       "      <td>1.999758</td>\n",
       "      <td>0.011464</td>\n",
       "      <td>1.267048</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(soup)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.050527</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.096756</td>\n",
       "      <td>1.914955</td>\n",
       "      <td>0.011020</td>\n",
       "      <td>1.051182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>56</th>\n",
       "      <td>(milk)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.023597</td>\n",
       "      <td>0.182099</td>\n",
       "      <td>1.910382</td>\n",
       "      <td>0.011245</td>\n",
       "      <td>1.106099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.179709</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.028796</td>\n",
       "      <td>0.160237</td>\n",
       "      <td>1.837830</td>\n",
       "      <td>0.013128</td>\n",
       "      <td>1.086988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.065858</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.027596</td>\n",
       "      <td>0.419028</td>\n",
       "      <td>1.757904</td>\n",
       "      <td>0.011898</td>\n",
       "      <td>1.310962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.068391</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.020931</td>\n",
       "      <td>0.306043</td>\n",
       "      <td>1.757755</td>\n",
       "      <td>0.009023</td>\n",
       "      <td>1.190117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.040928</td>\n",
       "      <td>0.171700</td>\n",
       "      <td>1.747522</td>\n",
       "      <td>0.017507</td>\n",
       "      <td>1.088672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.021997</td>\n",
       "      <td>0.223881</td>\n",
       "      <td>1.727704</td>\n",
       "      <td>0.009265</td>\n",
       "      <td>1.121499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.071457</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.021197</td>\n",
       "      <td>0.296642</td>\n",
       "      <td>1.703760</td>\n",
       "      <td>0.008756</td>\n",
       "      <td>1.174209</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.027863</td>\n",
       "      <td>0.292308</td>\n",
       "      <td>1.678867</td>\n",
       "      <td>0.011267</td>\n",
       "      <td>1.167018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>(cooking oil)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.051060</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.394256</td>\n",
       "      <td>1.653978</td>\n",
       "      <td>0.007960</td>\n",
       "      <td>1.257349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>(chicken)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.059992</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.022797</td>\n",
       "      <td>0.380000</td>\n",
       "      <td>1.594172</td>\n",
       "      <td>0.008497</td>\n",
       "      <td>1.228438</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.035729</td>\n",
       "      <td>0.149888</td>\n",
       "      <td>1.572463</td>\n",
       "      <td>0.013007</td>\n",
       "      <td>1.064189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.035462</td>\n",
       "      <td>0.203675</td>\n",
       "      <td>1.571779</td>\n",
       "      <td>0.012900</td>\n",
       "      <td>1.093043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.047994</td>\n",
       "      <td>0.201342</td>\n",
       "      <td>1.553774</td>\n",
       "      <td>0.017105</td>\n",
       "      <td>1.089850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.025197</td>\n",
       "      <td>0.144717</td>\n",
       "      <td>1.522468</td>\n",
       "      <td>0.008647</td>\n",
       "      <td>1.058066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.129583</td>\n",
       "      <td>0.032129</td>\n",
       "      <td>0.196094</td>\n",
       "      <td>1.513276</td>\n",
       "      <td>0.010898</td>\n",
       "      <td>1.082736</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.068391</td>\n",
       "      <td>0.024397</td>\n",
       "      <td>0.102349</td>\n",
       "      <td>1.496530</td>\n",
       "      <td>0.008095</td>\n",
       "      <td>1.037830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.095054</td>\n",
       "      <td>0.033729</td>\n",
       "      <td>0.141499</td>\n",
       "      <td>1.488616</td>\n",
       "      <td>0.011071</td>\n",
       "      <td>1.054100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.170911</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.021997</td>\n",
       "      <td>0.128705</td>\n",
       "      <td>1.476173</td>\n",
       "      <td>0.007096</td>\n",
       "      <td>1.047650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.095321</td>\n",
       "      <td>0.022930</td>\n",
       "      <td>0.139951</td>\n",
       "      <td>1.468215</td>\n",
       "      <td>0.007312</td>\n",
       "      <td>1.051893</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>(whole wheat rice)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.058526</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.020131</td>\n",
       "      <td>0.343964</td>\n",
       "      <td>1.442993</td>\n",
       "      <td>0.006180</td>\n",
       "      <td>1.160960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.059725</td>\n",
       "      <td>0.343032</td>\n",
       "      <td>1.439085</td>\n",
       "      <td>0.018223</td>\n",
       "      <td>1.159314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>65</th>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>0.163845</td>\n",
       "      <td>0.098254</td>\n",
       "      <td>0.023064</td>\n",
       "      <td>0.140765</td>\n",
       "      <td>1.432669</td>\n",
       "      <td>0.006965</td>\n",
       "      <td>1.049476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>(cake)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.081056</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.027463</td>\n",
       "      <td>0.338816</td>\n",
       "      <td>1.421397</td>\n",
       "      <td>0.008142</td>\n",
       "      <td>1.151921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>0.174110</td>\n",
       "      <td>0.087188</td>\n",
       "      <td>0.021464</td>\n",
       "      <td>0.123277</td>\n",
       "      <td>1.413918</td>\n",
       "      <td>0.006283</td>\n",
       "      <td>1.041163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>59</th>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>0.071457</td>\n",
       "      <td>0.238368</td>\n",
       "      <td>0.023597</td>\n",
       "      <td>0.330224</td>\n",
       "      <td>1.385352</td>\n",
       "      <td>0.006564</td>\n",
       "      <td>1.137144</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            antecedents          consequents  antecedent support  \\\n",
       "11          (spaghetti)        (ground beef)            0.174110   \n",
       "66          (olive oil)          (spaghetti)            0.065858   \n",
       "62      (mineral water)               (soup)            0.238368   \n",
       "56               (milk)  (frozen vegetables)            0.129583   \n",
       "33               (eggs)            (burgers)            0.179709   \n",
       "38          (olive oil)      (mineral water)            0.065858   \n",
       "85           (tomatoes)          (spaghetti)            0.068391   \n",
       "9       (mineral water)        (ground beef)            0.238368   \n",
       "73        (ground beef)               (milk)            0.098254   \n",
       "83             (shrimp)          (spaghetti)            0.071457   \n",
       "37  (frozen vegetables)          (spaghetti)            0.095321   \n",
       "93        (cooking oil)      (mineral water)            0.051060   \n",
       "71            (chicken)      (mineral water)            0.059992   \n",
       "19      (mineral water)  (frozen vegetables)            0.238368   \n",
       "21          (spaghetti)               (milk)            0.174110   \n",
       "7       (mineral water)               (milk)            0.238368   \n",
       "46          (spaghetti)           (pancakes)            0.174110   \n",
       "29          (chocolate)               (milk)            0.163845   \n",
       "50      (mineral water)           (tomatoes)            0.238368   \n",
       "24      (mineral water)           (pancakes)            0.238368   \n",
       "75       (french fries)            (burgers)            0.170911   \n",
       "68          (chocolate)  (frozen vegetables)            0.163845   \n",
       "89   (whole wheat rice)      (mineral water)            0.058526   \n",
       "0           (spaghetti)      (mineral water)            0.174110   \n",
       "65          (chocolate)        (ground beef)            0.163845   \n",
       "41               (cake)      (mineral water)            0.081056   \n",
       "80          (spaghetti)            (burgers)            0.174110   \n",
       "59             (shrimp)      (mineral water)            0.071457   \n",
       "\n",
       "    consequent support   support  confidence     lift2  leverage  conviction  \n",
       "11            0.098254  0.039195    0.225115  2.291162  0.022088    1.163716  \n",
       "66            0.174110  0.022930    0.348178  1.999758  0.011464    1.267048  \n",
       "62            0.050527  0.023064    0.096756  1.914955  0.011020    1.051182  \n",
       "56            0.095321  0.023597    0.182099  1.910382  0.011245    1.106099  \n",
       "33            0.087188  0.028796    0.160237  1.837830  0.013128    1.086988  \n",
       "38            0.238368  0.027596    0.419028  1.757904  0.011898    1.310962  \n",
       "85            0.174110  0.020931    0.306043  1.757755  0.009023    1.190117  \n",
       "9             0.098254  0.040928    0.171700  1.747522  0.017507    1.088672  \n",
       "73            0.129583  0.021997    0.223881  1.727704  0.009265    1.121499  \n",
       "83            0.174110  0.021197    0.296642  1.703760  0.008756    1.174209  \n",
       "37            0.174110  0.027863    0.292308  1.678867  0.011267    1.167018  \n",
       "93            0.238368  0.020131    0.394256  1.653978  0.007960    1.257349  \n",
       "71            0.238368  0.022797    0.380000  1.594172  0.008497    1.228438  \n",
       "19            0.095321  0.035729    0.149888  1.572463  0.013007    1.064189  \n",
       "21            0.129583  0.035462    0.203675  1.571779  0.012900    1.093043  \n",
       "7             0.129583  0.047994    0.201342  1.553774  0.017105    1.089850  \n",
       "46            0.095054  0.025197    0.144717  1.522468  0.008647    1.058066  \n",
       "29            0.129583  0.032129    0.196094  1.513276  0.010898    1.082736  \n",
       "50            0.068391  0.024397    0.102349  1.496530  0.008095    1.037830  \n",
       "24            0.095054  0.033729    0.141499  1.488616  0.011071    1.054100  \n",
       "75            0.087188  0.021997    0.128705  1.476173  0.007096    1.047650  \n",
       "68            0.095321  0.022930    0.139951  1.468215  0.007312    1.051893  \n",
       "89            0.238368  0.020131    0.343964  1.442993  0.006180    1.160960  \n",
       "0             0.238368  0.059725    0.343032  1.439085  0.018223    1.159314  \n",
       "65            0.098254  0.023064    0.140765  1.432669  0.006965    1.049476  \n",
       "41            0.238368  0.027463    0.338816  1.421397  0.008142    1.151921  \n",
       "80            0.087188  0.021464    0.123277  1.413918  0.006283    1.041163  \n",
       "59            0.238368  0.023597    0.330224  1.385352  0.006564    1.137144  "
      ]
     },
     "execution_count": 397,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 为了方便对比，rules2取偶数行\n",
    "rules2_even = rules2.iloc[np.array(range(0,94,2))][:rules.shape[0]]\n",
    "rules2_even"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 398,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>关联规则</th>\n",
       "      <th>lift1</th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>lift2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{ground beef} -&gt; {spaghetti}</td>\n",
       "      <td>2.291</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>2.291162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{olive oil} -&gt; {spaghetti}</td>\n",
       "      <td>2.000</td>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>1.999758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{soup} -&gt; {mineral water}</td>\n",
       "      <td>1.915</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(soup)</td>\n",
       "      <td>1.914955</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>{burgers} -&gt; {eggs}</td>\n",
       "      <td>1.838</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>1.910382</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>{tomatoes} -&gt; {spaghetti}</td>\n",
       "      <td>1.758</td>\n",
       "      <td>(eggs)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>1.837830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>{olive oil} -&gt; {mineral water}</td>\n",
       "      <td>1.758</td>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.757904</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>{ground beef} -&gt; {mineral water}</td>\n",
       "      <td>1.748</td>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>1.757755</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>{shrimp} -&gt; {spaghetti}</td>\n",
       "      <td>1.704</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>1.747522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>{frozen vegetables} -&gt; {spaghetti}</td>\n",
       "      <td>1.679</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>1.727704</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>{cooking oil} -&gt; {mineral water}</td>\n",
       "      <td>1.654</td>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>1.703760</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>{chicken} -&gt; {mineral water}</td>\n",
       "      <td>1.594</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>1.678867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>{frozen vegetables} -&gt; {mineral water}</td>\n",
       "      <td>1.572</td>\n",
       "      <td>(cooking oil)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.653978</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>{milk} -&gt; {spaghetti}</td>\n",
       "      <td>1.572</td>\n",
       "      <td>(chicken)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.594172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>{milk} -&gt; {mineral water}</td>\n",
       "      <td>1.554</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>1.572463</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>{pancakes} -&gt; {spaghetti}</td>\n",
       "      <td>1.522</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>1.571779</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>{tomatoes} -&gt; {mineral water}</td>\n",
       "      <td>1.497</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>1.553774</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>{pancakes} -&gt; {mineral water}</td>\n",
       "      <td>1.489</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>1.522468</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>{burgers} -&gt; {french fries}</td>\n",
       "      <td>1.476</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(milk)</td>\n",
       "      <td>1.513276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>{whole wheat rice} -&gt; {mineral water}</td>\n",
       "      <td>1.443</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(tomatoes)</td>\n",
       "      <td>1.496530</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>{mineral water} -&gt; {spaghetti}</td>\n",
       "      <td>1.439</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(pancakes)</td>\n",
       "      <td>1.488616</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>{spaghetti} -&gt; {mineral water}</td>\n",
       "      <td>1.439</td>\n",
       "      <td>(french fries)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>1.476173</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>{cake} -&gt; {mineral water}</td>\n",
       "      <td>1.421</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(frozen vegetables)</td>\n",
       "      <td>1.468215</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>{shrimp} -&gt; {mineral water}</td>\n",
       "      <td>1.385</td>\n",
       "      <td>(whole wheat rice)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.442993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>{chocolate} -&gt; {mineral water}</td>\n",
       "      <td>1.348</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.439085</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>{frozen smoothie} -&gt; {mineral water}</td>\n",
       "      <td>1.342</td>\n",
       "      <td>(chocolate)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>1.432669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>{low fat yogurt} -&gt; {mineral water}</td>\n",
       "      <td>1.316</td>\n",
       "      <td>(cake)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.421397</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>{eggs} -&gt; {mineral water}</td>\n",
       "      <td>1.189</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(burgers)</td>\n",
       "      <td>1.413918</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>{burgers} -&gt; {mineral water}</td>\n",
       "      <td>1.174</td>\n",
       "      <td>(shrimp)</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>1.385352</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                      关联规则  lift1          antecedents  \\\n",
       "0             {ground beef} -> {spaghetti}  2.291          (spaghetti)   \n",
       "1               {olive oil} -> {spaghetti}  2.000          (olive oil)   \n",
       "2                {soup} -> {mineral water}  1.915      (mineral water)   \n",
       "3                      {burgers} -> {eggs}  1.838               (milk)   \n",
       "4                {tomatoes} -> {spaghetti}  1.758               (eggs)   \n",
       "5           {olive oil} -> {mineral water}  1.758          (olive oil)   \n",
       "6         {ground beef} -> {mineral water}  1.748           (tomatoes)   \n",
       "7                  {shrimp} -> {spaghetti}  1.704      (mineral water)   \n",
       "8       {frozen vegetables} -> {spaghetti}  1.679        (ground beef)   \n",
       "9         {cooking oil} -> {mineral water}  1.654             (shrimp)   \n",
       "10            {chicken} -> {mineral water}  1.594  (frozen vegetables)   \n",
       "11  {frozen vegetables} -> {mineral water}  1.572        (cooking oil)   \n",
       "12                   {milk} -> {spaghetti}  1.572            (chicken)   \n",
       "13               {milk} -> {mineral water}  1.554      (mineral water)   \n",
       "14               {pancakes} -> {spaghetti}  1.522          (spaghetti)   \n",
       "15           {tomatoes} -> {mineral water}  1.497      (mineral water)   \n",
       "16           {pancakes} -> {mineral water}  1.489          (spaghetti)   \n",
       "17             {burgers} -> {french fries}  1.476          (chocolate)   \n",
       "18   {whole wheat rice} -> {mineral water}  1.443      (mineral water)   \n",
       "19          {mineral water} -> {spaghetti}  1.439      (mineral water)   \n",
       "20          {spaghetti} -> {mineral water}  1.439       (french fries)   \n",
       "21               {cake} -> {mineral water}  1.421          (chocolate)   \n",
       "22             {shrimp} -> {mineral water}  1.385   (whole wheat rice)   \n",
       "23          {chocolate} -> {mineral water}  1.348          (spaghetti)   \n",
       "24    {frozen smoothie} -> {mineral water}  1.342          (chocolate)   \n",
       "25     {low fat yogurt} -> {mineral water}  1.316               (cake)   \n",
       "26               {eggs} -> {mineral water}  1.189          (spaghetti)   \n",
       "27            {burgers} -> {mineral water}  1.174             (shrimp)   \n",
       "\n",
       "            consequents     lift2  \n",
       "0         (ground beef)  2.291162  \n",
       "1           (spaghetti)  1.999758  \n",
       "2                (soup)  1.914955  \n",
       "3   (frozen vegetables)  1.910382  \n",
       "4             (burgers)  1.837830  \n",
       "5       (mineral water)  1.757904  \n",
       "6           (spaghetti)  1.757755  \n",
       "7         (ground beef)  1.747522  \n",
       "8                (milk)  1.727704  \n",
       "9           (spaghetti)  1.703760  \n",
       "10          (spaghetti)  1.678867  \n",
       "11      (mineral water)  1.653978  \n",
       "12      (mineral water)  1.594172  \n",
       "13  (frozen vegetables)  1.572463  \n",
       "14               (milk)  1.571779  \n",
       "15               (milk)  1.553774  \n",
       "16           (pancakes)  1.522468  \n",
       "17               (milk)  1.513276  \n",
       "18           (tomatoes)  1.496530  \n",
       "19           (pancakes)  1.488616  \n",
       "20            (burgers)  1.476173  \n",
       "21  (frozen vegetables)  1.468215  \n",
       "22      (mineral water)  1.442993  \n",
       "23      (mineral water)  1.439085  \n",
       "24        (ground beef)  1.432669  \n",
       "25      (mineral water)  1.421397  \n",
       "26            (burgers)  1.413918  \n",
       "27      (mineral water)  1.385352  "
      ]
     },
     "execution_count": 398,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对比两种工具计算的关联规则和lift\n",
    "contrast = pd.concat([rules.reset_index(),rules2_even.reset_index()[:28]],axis=1)\n",
    "contrast[['关联规则','lift1','antecedents','consequents','lift2']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 402,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>关联规则</th>\n",
       "      <th>lift1</th>\n",
       "      <th>antecedents</th>\n",
       "      <th>consequents</th>\n",
       "      <th>lift2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>{ground beef} -&gt; {spaghetti}</td>\n",
       "      <td>2.291</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>(ground beef)</td>\n",
       "      <td>2.291162</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>{olive oil} -&gt; {spaghetti}</td>\n",
       "      <td>2.000</td>\n",
       "      <td>(olive oil)</td>\n",
       "      <td>(spaghetti)</td>\n",
       "      <td>1.999758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>{soup} -&gt; {mineral water}</td>\n",
       "      <td>1.915</td>\n",
       "      <td>(mineral water)</td>\n",
       "      <td>(soup)</td>\n",
       "      <td>1.914955</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           关联规则  lift1      antecedents    consequents  \\\n",
       "0  {ground beef} -> {spaghetti}  2.291      (spaghetti)  (ground beef)   \n",
       "1    {olive oil} -> {spaghetti}  2.000      (olive oil)    (spaghetti)   \n",
       "2     {soup} -> {mineral water}  1.915  (mineral water)         (soup)   \n",
       "\n",
       "      lift2  \n",
       "0  2.291162  \n",
       "1  1.999758  \n",
       "2  1.914955  "
      ]
     },
     "execution_count": 402,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对比前三行\n",
    "contrast[['关联规则','lift1','antecedents','consequents','lift2']][:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<font color=red size=5>根据以上表格分析，具有相同关联规则的两者lift值十分相似，具有一定的参考价值。</font>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.0 64-bit ('Bi_env': venv)",
   "language": "python",
   "name": "python38064bitbienvvenvba07af95a1bb4b078aa8134bba84dff2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
